<template>
  <div class="container">
    <baseTable
      :tableSetting="workTicketSetting"
      :tableData="workTicketData"
      ref="workTicket"
    ></baseTable>
  </div>
</template>

<script>
/* 工单关联的工作票列表 */
import {
  queryTicketListApi, //根据工单id查询关联的工作票列表
} from "@/api/orderManagement/common";
export default {
  props: {
    orderId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      workTicketData: [],
      workTicketSetting: {
        title: "",
        indexShow: true, // 序号显示
        autoHeight:true,
        column: [
          {
            label: "工作票票号",
            prop: "code",
            width: "110px",
          },
          {
            label: "标题",
            prop: "title",
          },
          {
            label: "工作票类型",
            prop: "type",
            formatter: (row) => {
              let value = row.type;
              return (
                this.$store.getters["fineDirtDataName"](
                  "ticket_work_type",
                  value
                ) || value
              );
            },
          },
          {
            label: "工作负责人",
            prop: "directorName",
            width: "110px",
          },
          {
            label: "工作班组",
            prop: "team",
          },
          {
            label: "工作地点",
            prop: "locationName",
          },
          {
            label: "计划开始时间",
            prop: "estimatedStartTime",
            width: "150px",
          },
          {
            label: "计划结束时间",
            prop: "estimatedEndTime",
            width: "150px",
          },
          {
            label: "工作许可时间",
            prop: "oPermitTime",
            width: "150px",
          },
          {
            label: "工作终结时间",
            prop: "oEndTime",
            width: "150px",
          },
          {
            label: "状态",
            prop: "status",
            formatter: (row) => {
              let value = row.status;
              return (
                this.$store.getters["fineDirtDataName"](
                  "ticket_work_status",
                  value
                ) || value
              );
            },
            width: "90px",
          },
        ],
        data: [],
        rowClick: async (row) => {
          /* 工作票详情 */
          let { id, ticketType } = row;
          let routerForm = {
            val: id,
            ticketType,
            pageType: "edit",
          };
          this.goToDetails(routerForm);
        },
      },
    };
  },
  created() {},
  mounted() {
    this.getWorkingTicketData();
  },
  methods: {
    //获取工作票信息
    getWorkingTicketData() {
      queryTicketListApi(this.orderId).then((res) => {
        let data = res.data || [];
        this.workTicketData = data;
        this.$emit("haveData", data.length > 0 ? true : false);
        if (data.length > 0) {
          this.$refs.workTicket.setTableData(data);
        }
      });
    },
    goToDetails(data) {
      const { href } = this.$router.resolve({
        name: "workTicketProcessingDetails",
        query: data,
      });
      window.open(href, "_blank");
    },
  },
};
</script>